package com.device.common.util;

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author lgb
 * @date 2020-8-21
 * @说明 时间工具
 **/
public class DateUtil {

	/**
	 * @return 获取日期字符串
	 **/
	public static String formatDate(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(new Date());
    }
	/**
	 * @return 获取时间字符串
	 **/
	public static String formatTime(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(new Date());
    }
	/**
	 * @return 获取时间字符串
	 **/
	public static String formatTime(Date date){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
	/**
	 * @return 获取时间字符串
	 **/
	public static Date formatTime(String time){
		Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
        	date = sdf.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}